package com.yidu.TAManagement.mapper;

import com.yidu.BusinessParament.entity.Fund;
import com.yidu.TAManagement.entity.Ta;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *TA交易数据持久层接口
 * @author 赵俊豪
 * @date 2022/12/11 13:33
 **/
@Mapper
public interface TaMapper {
    /**
     * 查询TA表
     * @param map map集合
     * @return
     */
    @Select ("SELECT t.*,c.accountName,f.fundName FROM cash c JOIN (SELECT * FROM ta where 1=1 ${strWhere})t ON t.cashId=c.cashId JOIN fund f ON t.fundId = f.fundId  LIMIT #{page},#{limit}")
    public List<Ta> SelectTa(Map map);

    /**
     * 分页查TA行数 模糊查询后的行数
     * @param map map集合
     * @return
     */
    @Select("select count(*) from ta where 1=1 ${strWhere}")
    public int SelectTaCount(Map map);

    /**
     * 删除TA数据
     * @param taId TAId
     * @return
     */
    public int DeleteTa(List taId);

    /**
     * 新增TA交易数据
     * @param ta TA对象
     * @return
     */
    @Insert("insert into ta(taId,cashId,fundId,dealType,quantity,cost,dealTime,unitPrice,endTime," +
            "commissionAgents,money,practicalMoney,dealState,Remark) values(#{taId},#{cashId},#{fundId}" +
            ",#{dealType},#{quantity},#{cost},#{dealTime},#{unitPrice},#{endTime},#{commissionAgents}," +
            "#{money},#{practicalMoney},#{dealState},#{Remark})")
    public int InsertTa(Ta ta);

    /**
     * 查询最大ID的方法
     * @return
     */
    @Select ("SELECT taId FROM ta ORDER BY taId  DESC LIMIT 1")
    public String SelectMaxtaId();

    /**
     * 修改TA交易数据
     * @param ta TA对象
     * @return
     */
    @Update("update ta set cashId=#{cashId},fundId=#{fundId},dealType=#{dealType},quantity=#{quantity}," +
            "cost=#{cost},dealTime=#{dealTime},unitPrice=#{unitPrice},endTime=#{endTime},commissionAgents=#{commissionAgents}," +
            "money=#{money},practicalMoney=#{practicalMoney},dealState=#{dealState},Remark=#{Remark} where " +
            "taId=#{taId}")
    public int UpdateTa(Ta ta);

    /**
     * 查询表是否有数据
     * @return
     */
    @Select ("select count(*) from ta")
    public int TALength();

    /**
     * 根据交易类型和交易时间和总金额删除ta交易数据
     * @param map map集合
     * @return
     */
    @Delete (" delete from ta where dealType=#{dealType} and dealTime=#{dealTime} and money=#{money}")
    public int DeleteTaLmport(Map map);

}
